package data.analysis.grammar.symbol;

import java.util.HashMap;
import java.util.Map;

public class ScopedSymbol extends Symbol implements Scope {
	private final Map<String,Symbol> table;

	public ScopedSymbol(String name, Type type, Scope defining) {
		super(name, type, defining);
		this.table = new HashMap<String,Symbol>();
	}

	@Override
	public boolean define(Symbol s) {
		if (table.containsKey(s.getName())) {
			return false;
		}
		table.put(s.getName(), s);
		return true;
	}

	@Override
	public Symbol resolve(String name) {
		return table.get(name);
	}
	
	@Override
	public Symbol[] getDefinitions() {
		return table.values().toArray(new Symbol[table.size()]);
	}
}
